/*
#include<iostream>
using namespace std;

class Fraction {
private:
    int numerator;
    int denominator;

public:
    Fraction() : numerator(0), denominator(1) {}
    Fraction(int num, int denom) : numerator(num), denominator(denom) {
        simplify();
    }

    void simplify() {
        int gcd = findGCD(numerator, denominator);
        numerator /= gcd;
        denominator /= gcd;
    }

    // 求a和b的最大公约数
    int findGCD(int a, int b) {
        return b == 0 ? a : findGCD(b, a % b);
    }

    friend bool valid(const Fraction& f);
    friend istream& operator>>(istream& is, Fraction& f);
    friend ostream& operator<<(ostream& out, const Fraction& f);

    friend Fraction operator+(const Fraction& f1, const Fraction& f2);
}

*/
#include "fraction.h"

#include <iostream>

using namespace std;

bool valid(const Fraction& f) {
    return f.denominator != 0;
}

istream& operator>>(istream& is, Fraction& f) {
    is >> f.numerator >> f.denominator;
    f.simplify();
    return is;
}

ostream& operator<<(ostream& os, const Fraction& f) {
    os << f.numerator << "/" << f.denominator;
    return os;
}

Fraction operator+(const Fraction& f1, const Fraction& f2) {
    Fraction result(f1.numerator * f2.denominator + f2.numerator * f1.denominator, f1.denominator * f2.denominator);
    return result;
}